package com.example.java.zuo.新手班.class02;


import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Objects;

/**
 * @Author : 佩萁
 * Description :前缀和
 * @Create : 2023/12/13 - 13:47
 */
public class Code01_PreSum {
    public static void main(String[] args) {
//        int[] a = {3, 2, -1, 6, 7, 2, -2};
//        RangeSum2(a);
//        System.out.println(rangeSum(0, 10));
        long l = Long.MAX_VALUE;
//        BigInteger bigInteger = BigInteger.valueOf(9223372036854775807);
        BigInteger num2 = new BigInteger("9876543210987654321098765432109876543210");
        System.out.println(num2);
        System.out.println(l+1); // -9223372036854775808
        System.out.println(l + 1 == Long.MIN_VALUE); // true
    }

    private static int[] preSum;

    public static void RangeSum2(int[] array) {
        int N = array.length;
        preSum = new int[N];
        preSum[0] = array[0];
        for (int i = 1; i < N; i++) {
            preSum[i] = preSum[i - 1] + array[i];
        }
    }

    public static int rangeSum(int L, int R) {
        if (L < 0 || R > preSum.length - 1) {
            return -1;
        }
        return L == 0 ? preSum[R] : preSum[R] - preSum[L - 1];
    }

}